import 'package:dio/dio.dart';
import 'package:flutterdemo/common/config/appConstant.dart';
import 'package:flutterdemo/common/data/index.dart';

class DioUtils {
  static void initDioInfo() {
    if (AppConstant.openBug) {
      DioUtil.openDebug();
    }
    // 配置网络参数.
    BaseOptions options = DioUtil.getDefOptions();
    options.baseUrl = AppConstant.baseUrl;
    HttpConfig config = new HttpConfig(options: options);
    DioUtil().setConfig(config);
  }

  /// 网络请求的基类
  static BaseResp request(String method, String path,
      {data, Options options, CancelToken cancelToken}) {
    BaseResp response = DioUtil.getInstance().request(method, path,
        data: data, options: options, cancelToken: cancelToken) as BaseResp;
    return response;
  }

  /// formData类型
  static BaseResp requestR(String method, String path,
      {data, Options options, CancelToken cancelToken}) {
    BaseResp response = DioUtil.getInstance().requestR(method, path,
        data: data, options: options, cancelToken: cancelToken) as BaseResp;
    return response;
  }
}
